Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var utilities = require('../utilities.js'); |
||
31 | describe('successful tests', function() { |
||
32 | // test example from README.md |
||
33 | var SuperClass = function() { |
||
34 | this.someProperty = 42; |
||
35 | }; |
||
36 | |||
37 | SuperClass.prototype.retMsg = function(msg) { |
||
38 | return msg; |
||
39 | }; |
||
40 | |||
41 | SuperClass.prototype.getSomeProp = function() { |
||
42 | return this.someProperty; |
||
43 | }; |
||
44 | |||
45 | // a class we want to inherit from SuperClass |
||
46 | var SomeClass = function() { |
||
47 | SuperClass.call(this); |
||
48 | }; |
||
49 | |||
50 | utilities.inherits(SomeClass, SuperClass); |
||
51 | |||
52 | SomeClass.prototype.flop = function(msg) { |
||
53 | return this.retMsg(msg); |
||
54 | }; |
||
55 | |||
56 | var someClass_instance = new SomeClass(); |
||
57 | // end test example from README.md |
||
58 | |||
59 | it("should be able to access inherited properties", function() { |
||
60 | expect(someClass_instance.someProperty).toEqual(42); |
||
61 | }); |
||
62 | |||
63 | it("should be able to run inherited methods", function() { |
||
64 | expect(someClass_instance.retMsg('hi')).toEqual('hi'); |
||
65 | }); |
||
66 | |||
67 | it("should be able to run inherited methods by using the this keyword", function() { |
||
68 | expect(someClass_instance.flop('hi')).toEqual('hi'); |
||
69 | }); |
||
70 | |||
71 | it("should be instance of SomeClass", function() { |
||
72 | expect((someClass_instance instanceof SomeClass)).toEqual(true); |
||
73 | }); |
||
74 | |||
75 | it("should be instance of SuperClass", function() { |
||
76 | expect((someClass_instance instanceof SuperClass)).toEqual(true); |
||
77 | }); |
||
78 | |||
79 | it("should set SuperClass contructor", function() { |
||
80 | expect(someClass_instance.constructor.super_ === SuperClass).toEqual(true); |
||
81 | }); |
||
82 | |||
83 | it("should set contructor", function() { |
||
84 | expect(someClass_instance.constructor === SomeClass).toEqual(true); |
||
85 | }); |
||
86 | }); |
||
87 | }); |